import { loginAPI } from '@/api/user'
import { getToken, setToken, removeToken } from '@/utils/auth'
export default {
  namespaced: true,
  state() {
    return {
      token: getToken() || ''
    }
  },
  mutations: {
    updateToken(state, token) {
      state.token = token
      setToken(token)
    },
    clearUserInfo(state) {
      state.token = ''
      removeToken()
    }
  },
  actions: {
    async doLogin(context, { username, password }) {
      console.log(username, password)
      const res = await loginAPI({ username, password })
      console.log(res)
      context.commit('updateToken', res.data.token)
    }
  }
}

